In [28]:
import pandas as pd
import numpy as np
In [3]:
rice = pd.read_csv("/Users/macbook/Documents/BTP/Notebook/BTP/Ricex_prepared2.csv")
rice.head()
Out[3]:
In [4]:
rice = rice.drop(["Unnamed: 0"],axis=1)
In [13]:
cols = list(rice.columns.values)
In [26]:
l = rice.shape[0]
b = rice.shape[1]
for row in range(0,l):
vals = np.zeros(18)
bx = False
for col in range(10,b-108,18):
if pd.isnull(rice.iloc[row,col]):
s = cols[col]
#print s
#print rice.iloc[row,col]
"""First calculate vals, if needed"""
if not bx:
n = 0
for i in range(10,b-108,18):
if (cols[i] != s and (not pd.isnull(rice.iloc[row,i]))):
n += 1
for j in range(i,i+18):
vals[j-i] += rice.iloc[row,j]
vals = vals/n
bx = True
"""Update all those 18 blanks using vals"""
for j in range(col,col+18):
rice.iloc[row,j] = vals[j-col]
In [27]:
rice.to_csv("Rice_Ready.csv")